'''
Description: 
Author: HowsenFisher
Date: 2021-04-12 09:52:30
LastEditTime: 2021-04-12 10:22:03
LastEditors: liutq
Reference: 
'''
import pyaudio,wave

class VoicePlayer:
    def __init__(self):
        print("初始化声音播放器")
        self.p = pyaudio.PyAudio()
        self.chunk_size = 1024 # 512
        self.audio_format = pyaudio.paInt16
        self.channels = 2
        self.rate = 44100
        self.playing_stream = self.p.open(format=self.audio_format,
                                            channels=self.channels,
                                            rate=self.rate,
                                            output=True,
                                            frames_per_buffer=self.chunk_size)
        print("声音播放器初始化完毕完毕")
    def play(self,voiceData):
        # print("播放声音")
        self.playing_stream.write(voiceData)
        
